package com.example.teesystem.entityDto;

import com.example.teesystem.common.utils.IssueUtil;
import com.example.teesystem.common.utils.TimeUtil;
import com.example.teesystem.entity.ExamPaper;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

/**
 * @author : NieYaShi
 * @version : v1.0
 * @createTime : 2022/4/11 10:24
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ExamPaperList {

    private Integer id;

    private String name;

    private String message;

    private String includeIssueType;

    private String includeIssueTypeName;

    private Integer level;

    private Integer isPublish;

    private String isPublishStr;

    private Integer isFinish;

    private String isFinishStr;

    private Integer isMark;

    private String isMarkStr;

    private Integer main;

    private String uploadTime;

    public ExamPaperList(ExamPaper examPaper) {
        BeanUtils.copyProperties(examPaper, this);

        includeIssueType = includeIssueType.trim();
        if (!includeIssueType.equals("")) {
            String[] typeStrs = includeIssueType.split("\\$");
            StringBuilder stringBuilder = new StringBuilder();
            for (int i = 0; i < typeStrs.length; i++) {
                if (!typeStrs[i].equals(" ")) {
                    stringBuilder.append(IssueUtil.getIssueTypeName(Integer.parseInt(typeStrs[i])));
                    stringBuilder.append("、");
                }
            }
            stringBuilder.delete(stringBuilder.length() - 1, stringBuilder.length());
            this.includeIssueTypeName = stringBuilder.toString();
        }else {
            this.includeIssueTypeName = "";
        }

        if (isPublish == 0){
            this.isPublishStr = "未发布";
        }else {
            this.isPublishStr = "已发布";
        }

        if (isFinish == 0){
            this.isFinishStr = "未完成考试";
        }else {
            this.isFinishStr = "已考试结束";
        }

        if (isMark == 0){
            this.isMarkStr = "未完成阅卷";
        }else {
            this.isMarkStr = "已完成阅卷";
        }

        this.uploadTime = TimeUtil.dateToString(examPaper.getUploadTime());
    }
}
